<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>百知科技</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/login2.css">
	<script src="${pageContext.request.contextPath}/js/jquery-1.12.4.js" type="text/javascript"></script>
</head>

<body>

<div id="wrap" >

	<div id="header">
		<div class="logo">
			<img src="images/logo.png" width='200px'/>
		</div>
	</div>


	<div id="mainer">

		<div class="login_main">

			<div class="login_img"><img src="images/bg2.jpg" width='550px'></div>

			<div class="login_box">
				<div class="login_tit">百知科技用户注册</div>
				<form action="http://localhost:8082/work/addUser" method="get" id="form1">
					<div class="item">
						<input name="phone" type="text" id="txtUserName" class="input" placeholder="手机号">
					</div>
					<div class="item">
						<input name="password" type="password" id="txtPassword" class="input" placeholder="密码">
					</div>
					<div class="item">
						<input name="validate" class="input2" placeholder="验证码"/> <input type="button" id ="send" class="send" value="发送" />
					</div>
					<div class="item">
						<input type="button" name="btnLogin" value="注册" id="btnLogin" class="btn" style="margin-top: 10px;">
						<span id="msg"></span>
					</div>
				</form>
			</div>
		</div>
	</div>

	<div id="footer">
		<div class="footbox">
			<a href="">北京百知科技集团</a>
		</div>
	</div>
</div>
<script type="text/javascript">
	$(function () {
		$("#send").click(function () {
			var phone = $("input[name=phone]").val();
			var password = $("input[name=password]").val();
			var validate = $("input[name=validate]").val();
			console.log("send");
			console.log(phone);
			console.log(password);
			console.log(validate);
			$.ajax({
				url: "${pageContext.request.contextPath}/user/send",
				data: '{"phone":"' + phone + '","password":"' + password + '","validate":"' + validate + '"}',
				type: "post",
				dataType: "json",
				contentType:"application/json",
				success:function (result) {
					if(result.status == "success"){
						console.log(result);
						//登录成功，跳转到主界面
						//location.href="${pageContext.request.contextPath}/main.jsp";
						$("#msg").html("验证码已发送");
					}else{
						console.log(result);
						//登录失败，回显错误信息
						$("#msg").html("注册失败");
					}
				}
			});
		});
		//注册按钮
		$("#btnLogin").click(function () {
			var phone = $("input[name=phone]").val();
			var password = $("input[name=password]").val();
			var validate = $("input[name=validate]").val();
			$.ajax({
				url: "${pageContext.request.contextPath}/user/register",
				data: '{"phone":"' + phone + '","password":"' + password + '","validate":"' + validate + '"}',
				type: "post",
				dataType: "json",
				contentType:"application/json",
				success:function (result) {
					if(result.status == "success"){
						console.log(result);
						//登录成功，跳转到主界面
						//location.href="${pageContext.request.contextPath}/main.jsp";
						$("#msg").html("注册成功！");
					}else{
						console.log(result);
						//登录失败，回显错误信息
						$("#msg").html("注册失败！");
					}
				}
			});
		});

	})

</script>
</body>

</html>